<template>
  <a-card :bordered="false">

<!-- 页头区域-->
 <a-page-header
    style="border: 1px solid rgb(235, 237, 240)"
  >
   <p style="float:left"><b><font size="4">当前品类:{{this.$route.query.parentName}}</font></b>&nbsp; &nbsp;</p>
   <p style="float:left"><b><font size="4">业务类型:{{this.ordertypeString}} </font></b>&nbsp; &nbsp;</p>
   <p><b><font size="4">工艺类型:{{this.$route.query.categoryName}} </font></b></p>
 </a-page-header>

<br>

<p><h3><b>添加阶梯售价</b></h3></p>

    <!-- 操作按钮区域 -->

    <!-- table区域-begin -->
    <div>

  <a-list
    class="demo-loadmore-list"
    :loading="loading"
    item-layout="horizontal"
    :data-source="data"
  >
    <a-list-item slot="renderItem" slot-scope="item, index">
        大于等于: <a-input  v-model="item.minNumbers"  disabled="true" style="width: 150px"></a-input>件--
          小于: <a-input  v-model="item.maxNumbers"  disabled="true" style="width: 150px"></a-input>件&nbsp;&nbsp;
               <a-input  v-model="item.price"  disabled="true"  style="width: 150px"></a-input>元
      <!-- {{item.minNumbers}} 件--
        {{item.maxNumbers}} 件&nbsp;&nbsp;
        {{item.price}} 元 -->
         <a-button   @click="deletethis(item.id)" >删除</a-button>
    </a-list-item>
  </a-list>
 <div>
   <br/>
    <a-button  style="width: 500px;height: 36px;margin-bottom: 10px"  @click="xianshi=true">添加</a-button>
   <br/>
    </div>

<div v-if="xianshi" style="margin-top: 10px">
    大于等于:<a-input v-model="minNumbers" style="width: 150px"/> 件--
   小于: <a-input v-model="maxNumbers" style="width: 150px"/> 件
     <a-input v-model="price" style="width: 150px"/> 元

</div>
   <br/>
   <a-button type="primary" style="color: #F9D532;width: 80px;height: 36px;background: #333333;border-style: none;"  @click="addInerval">保存</a-button>&nbsp;&nbsp;
    <a-button  style="width: 80px;height: 36px;;"   @click="retrunshoujia">取消</a-button>
    </div>
    <!-- table区域-end -->
  </a-card>
</template>

<script>

  import {JeecgListMixin} from '@/mixins/JeecgListMixin'
  import JInput from '@/components/jeecg/JInput'
  import {getAction,postAction} from "../../api/manage";
  import Qs from 'qs'

  export default {
      name: "LaddeCostSetting",
    mixins: [JeecgListMixin],
    components: {
      JInput,
    },
    data() {
      return {
		  waicengId:'',
        xianshi:false,
        price:'',
        minNumbers:'',
        maxNumbers:'',
        data:[],
        ordertypeString:'',
        description: '这是新增装箱单',
        boxName: '', // 装箱单名称
        remark: '', // 备注
        queryParam: {},
        recycleBinVisible: false,
        productList: [], // 产品列表
        columns: [
          // {
          //   title: '序号',
          //   dataIndex: '',
          //   key: 'rowIndex',
          //   width: 60,
          //   sorter: true,
          //   align: "center",
          //   customRender: function (t, r, index) {
          //     return parseInt(index) + 1;
          //   }
          // },
          {
            title: '品类',
            align: "center",
            dataIndex: 'parentName',
            width: 120,
            sorter: true
          },
          {
            title: '业务类型',
            align: "center",
            width: 80,
            dataIndex: 'businessType',
            sorter: true,
                 customRender: (businessType) => {
              //字典值替换通用方法
              if(businessType==0)
              return "个定定制";
              else  if(businessType==1)
              return "团体定制";
              else
              return "标码加工";
            }
          },
          {
            title: '工艺类型',
            align: "center",
            width: 100,
            dataIndex: 'categoryName'
          },
          {
            title: '新增时间',
            align: "center",
            width: 100,
            dataIndex: 'createTime'
          },
          {
            title: '状态',
            align: "center",
            width: 100,
            dataIndex: 'status',
                   customRender: (status) => {
              //字典值替换通用方法
              if(status==0)
              return "未设置";
              else  if(status==1)
              return "已设置";
            }
          },
     {
            title: '设置售价',
            dataIndex: 'action',
              width: 100,
            align: "center",
            scopedSlots: {
              filterDropdown: 'filterDropdown',
              filterIcon: 'filterIcon',
              customRender: 'action'},
          }
        ],
        url: {
          list: "/TechnologyCostManage/costInervallist?pricesystemFactoryId="+this.$route.query.id,
          delete:"/TechnologyCostManage/deletecostInerval",
          add:"/TechnologyCostManage/addcostInerval"
        },
      }
    },
    computed: {
      /*importExcelUrl: function () {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }*/
    },
    created() {
		this.waicengId=this.$route.query.waicengId;
        if(this.$route.query.businessType==0)
         this.ordertypeString="个定定制"
         else  if(this.$route.query.businessType==1)
          this.ordertypeString="团体定制"
           else  if(this.$route.query.businessType==2)
          this.ordertypeString="标码加工"

          this.getpriceInervallist();
    },
    methods: {
//点击取消后回到售价列表
 retrunshoujia(){
    this.$router.push({path:'/TechnologyCostManage',query:{
			 id:this.waicengId
		}
          })
 },
      addInerval(){
         var minnum = this.minNumbers*1;
        var maxnum = this.maxNumbers*1;
        var reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
        if(!(/(^[1-9]\d*$)/.test(this.minNumbers))){
          this.$message.warning("最小件数必须为正整数");
          return
        }
        if(!(/(^[1-9]\d*$)/.test(this.maxNumbers))){
          this.$message.warning("最大件数必须为正整数");
          return
        }
        if(minnum>maxnum){
          this.$message.warning("最小件数不能超过最大件数");
          return
        }
        if(!reg.test(this.price)){
          this.$message.warning("请输入正确格式的售价金额");
          return;
        }
        let formdata={
            'pricesystemFactoryId':this.$route.query.id,
            'minNumbers':this.minNumbers,
             'maxNumbers':this.maxNumbers,
              'price':this.price
        }
              postAction(this.url.add,formdata).then((res)=>{
              if(res.success){
                 this.$message.success(res.message);
                 this.getpriceInervallist();
                 this.xianshi=false;
                 this.minNumbers= this.maxNumbers;
                   this.maxNumbers='';
                     this.price='';
              } else{
               this.$message.error(res.message);
              }

              })
      },
      deletethis(id){
             getAction(this.url.delete,{id:id}).then((res)=>{
              if(res.success){
                 this.$message.success(res.message);
                 this.getpriceInervallist();
              } else{
               this.$message.error(res.message);
              }

              })
      },
     getpriceInervallist(){
        getAction(this.url.list).then((res)=>{
              if(res.success){
                this.data=res.result;
              } })

     },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>